package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.PolicyCourierAddDTO;
import org.jsola.hr.dto.PolicyCourierUpdateDTO;
import org.jsola.hr.entity.PolicyCourierDO;
import org.jsola.hr.query.PolicyCourierQuery;
import org.jsola.hr.service.IPolicyCourierService;
import org.jsola.hr.vo.PolicyCourierVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 政策速递
 *
 * @author zhr
 */
@Component
public class PolicyCourierTestHelper extends BaseTestHelper {
    
    @Autowired
    private IPolicyCourierService policyCourierService;

    /**
     * 生成add测试数据
     * @return PolicyCourierAddDTO
     */
    public PolicyCourierAddDTO getPolicyCourierAddDTO(){
        PolicyCourierAddDTO policyCourierAddDTO = new PolicyCourierAddDTO();
        policyCourierAddDTO.setTitle(getRandomValue("varchar",50));
        policyCourierAddDTO.setTypeCode(getRandomValue("varchar",32));
        policyCourierAddDTO.setAnnex(getRandomValue("varchar",1000));
        policyCourierAddDTO.setPolicyLevel(getRandomValue("varchar",5));
        policyCourierAddDTO.setContent(getRandomValue("mediumtext",2147483647));
        policyCourierAddDTO.setContentHasStyle(getRandomValue("mediumtext",2147483647));
        policyCourierAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        policyCourierAddDTO.setCompanyPermissions(getRandomValue("varchar",5000));
        policyCourierAddDTO.setCompanyPermissionsJson(getRandomValue("varchar",5000));
        return policyCourierAddDTO;
    }


    /**
     * 生成update测试数据
     * @return PolicyCourierUpdateDTO
     */
    public PolicyCourierUpdateDTO getPolicyCourierUpdateDTO(PolicyCourierVO policyCourierVO){
        return policyCourierService.selectDOById(policyCourierVO.getId(), SITE_ID).to(PolicyCourierUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return PolicyCourierQuery
     */
    public PolicyCourierQuery getPolicyCourierQuery() {
        PolicyCourierQuery policyCourierQuery = new PolicyCourierQuery();
        List<PolicyCourierDO> policyCourierDOList = policyCourierService.list(new PolicyCourierDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(policyCourierDOList)) {
            PolicyCourierDO policyCourierDO = policyCourierDOList.get(0);
            policyCourierQuery = policyCourierDO.to(PolicyCourierQuery.class);
        }
        return policyCourierQuery;
    }

    /**
     * 保存示例
     * @return PolicyCourierVO
     */
    public PolicyCourierVO savePolicyCourierExample(){
        PolicyCourierAddDTO addDTO = this.getPolicyCourierAddDTO();
        PolicyCourierVO policyCourierVO = policyCourierService.save(addDTO,buildTokenUser());
        return policyCourierVO;
    }


}

